import Vue from 'vue'
import Router from 'vue-router'
import Layout from '../layout/index'

Vue.use(Router)

// 解决当前页跳当前页报错
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

export const constantRouterMap = [
    { path: '/dataServerShowDoc',
    meta: { title: '查看文档', noCache: true },
    component: (resolve) => require(['@/views/ykp/dataServer/img'], resolve),
    hidden: true
  },
  { path: '/login',
    meta: { title: '登录', noCache: true },
    component: (resolve) => require(['@/views/login'], resolve),
    hidden: true
  },
  {
    path: '/401',
    component: (resolve) => require(['@/views/features/401'], resolve),
    hidden: true
  },

  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: (resolve) => require(['@/views/features/redirect'], resolve)
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    isShow:0,
    children: [
      {
        path: 'dashboard',
        component: (resolve) => require(['@/views/home'], resolve),
        name: 'Dashboard',
        meta: { title: '首页', icon: 'index', affix: true, noCache: true }
      }
    ]
  },
  {
    path: '/ykp',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        component: (resolve) => require(['@/views/ykp/index'], resolve),
        name: '首页',
        meta: { title: '首页'}
      }
    ]
  },
  {
    path: '/interfaceForwarding',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'home',
        component: (resolve) => require(['@/views/interfaceForwarding/home'], resolve),
        name: '首页',
        meta: { title: '首页'}
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'center',
        component: (resolve) => require(['@/views/system/user/center'], resolve),
        name: '个人中心',
        meta: { title: '个人中心' }
      }
    ]
  },
  {
    path: '/sxTjDet',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'sxTjpage',
        component: (resolve) => require(['@/views/adminCenter/matterAdmin/detile'], resolve),
        name: '事项统计详情',
        meta: { title: '事项统计详情'}
      }
    ]
  },
  {
    path: '/taskCen',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'noedit',
        component: (resolve) => require(['@/views/adminCenter/matterAdmin/taskCenterPageNoEdit'], resolve),
        name: '事项统计详情',
        meta: { title: '事项统计详情'}
      }
    ]
  },
  {
    path: '/skin',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'skinpage',
        component: (resolve) => require(['@/views/system/user/skin'], resolve),
        name: '切换皮肤',
        meta: { title: '切换皮肤' }
      }
    ]
  },
  {
    path: '/taskcenterPage',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'taskcenpage',
        component: (resolve) => require(['@/views/adminCenter/matterAdmin/taskCenterPage'], resolve),
        name: '',
        meta: { title: '' }
      }
    ]
  },
  {
    path: '/bindOut',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'bindOutParm',
        component: (resolve) => require(['@/views/adminCenter/matterAdmin/bindOutParm'], resolve),
        name: '',
        meta: { title: '' }
      }
    ]
  },
  // {
  //   path: '*',
  //   redirect: '/404',
  // },
  {
    path: '/404',
    component:Layout,
    hidden: true,
    children: [
      {
        path: '*',
        component: (resolve) => require(['@/views/features/404'], resolve)
      }
    ]
  },
]


const createRouter = () => new Router({
  mode: 'hash',
  // base: process.env.BASE_URL,
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

/*
解决:退出登录再登录后 控制台路由命命名重复警告问题

发现自己的name并没有重名,那么一般是后台动态路由导致的报错警告
动态路由一般来说是通过后端接口返回拿到数据,然后在路由守卫router.beforeEach中进行添加
addRoutes方法仅仅是帮你注入新的路由,并没有帮你剔除其他路由
*/

const router = createRouter();
// 重置路由
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // the relevant part
}

export default router

